/*
* Copyright (C) 2020 ~ 2023 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#include "MkRtp/MkRtpServerPool.h"
#include "MkEvent/MkEventPool.h"
#include "MkEvent/MkTimer.h"
#include "MkEvent/MkEvent.h"
#include <gtest/gtest.h>

TEST(MkRtpServerPool, RtpTest)
{
    CMkEventPool* pEventPool = new CMkEventPool;
    pEventPool->Start();
    CMkTimer* pTimer = new CMkTimer;
    pTimer->StartTimerThread();
    CMkRtpServerPool* pRtpPool = new CMkRtpServerPool(pEventPool, pTimer);
    Uint32 ErrorCode = pRtpPool->Start();
    EXPECT_EQ(ErrorCode, NoneError);
    CMkRtpTcpServer *pTcpServer = pRtpPool->GetFreeTcpServer();
    EXPECT_NE(nullptr, pTcpServer);
    CMkRtpUdpServer *pUdpServer = pRtpPool->GetFreeUdpServer();
    EXPECT_NE(nullptr, pUdpServer);

    MkPair<CMkRtpTcpServer*, CMkRtpUdpServer*> PairRtp = pRtpPool->GetFreeRtpServer();
    EXPECT_NE(nullptr, PairRtp.first);
    EXPECT_NE(nullptr, PairRtp.second);

    pTimer->StopTimerThread();
    pEventPool->Stop();
    pRtpPool->Stop();
    MkDelete(pRtpPool);
    MkDelete(pTimer);
    MkDelete(pEventPool);
}